package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMyJoinTaskActivityModel;
import com.wgts.wgts.mvp.presenter.IMyJoinTaskActivityPresenter;
import com.wgts.wgts.mvp.view.IMyJoinTaskActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.MyJoinTaskEntity;

import java.util.List;

/*
 *
 *
 */public class MyJoinTaskActivityPresenter implements IMyJoinTaskActivityPresenter {
     private IMyJoinTaskActivityView view;
     private IMyJoinTaskActivityModel model;
     private Integer pageIndex = 1;
     private Integer pageSize = 20;

    public MyJoinTaskActivityPresenter(IMyJoinTaskActivityView view, IMyJoinTaskActivityModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void MyJoinTask() {
        pageIndex = 1;
        model.myJoinTask(pageIndex, pageSize, new HttpResultSubscriber<List<MyJoinTaskEntity>>() {
            @Override
            public void onSuccess(List<MyJoinTaskEntity> myJoinTaskEntities) {
                if (myJoinTaskEntities.size() < pageSize){
                    view.myJoinTask(myJoinTaskEntities, true);
                }else {
                    view.myJoinTask(myJoinTaskEntities, false);
                    pageIndex ++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void loadMore() {
       model.myJoinTask(pageIndex, pageSize, new HttpResultSubscriber<List<MyJoinTaskEntity>>() {
           @Override
           public void onSuccess(List<MyJoinTaskEntity> myJoinTaskEntities) {
               if (myJoinTaskEntities.size() < pageSize){
                   view.loadMore(myJoinTaskEntities, true);
               }else {
                   view.loadMore(myJoinTaskEntities, false);
                   pageIndex ++;
               }
           }

           @Override
           public void _onError(int status, String msg) {
                view.onError(status, msg);
           }
       });
    }
}
